/*
 * ActivityChooser.java
 *
 * Created on March 26, 2007, 3:08 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package Activity;

import Experience.*;
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemStateListener;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;

/**
 *
 * @author dmgreen
 */
public class ExerciseDescriptorScreen extends Form implements CommandListener, ItemStateListener {
    
    TextField myCaloriesTF, myTimeTF;
    int myCalories   = 0;
    int myTime     = 0;
    
    ExpUI myMIDlet = null;
    
    /** Creates a new instance of ActivityChooser */
    public ExerciseDescriptorScreen( MIDlet expsamp ) {
        super ("Describe Exercise");
        
        myMIDlet = (ExpUI) expsamp;
        
        myCaloriesTF   = new TextField("Calories"  , "", 5, TextField.NUMERIC);
        myTimeTF     = new TextField("Time"    , "", 5, TextField.NUMERIC);
        
        this.append("Please describe your exercise:");
        this.append(myCaloriesTF);
        this.append(myTimeTF);
        this.setItemStateListener(this);
        
        this.addCommand(new Command("Next", Command.OK, 1));
        this.setCommandListener(this);
        
    }
 
    public void commandAction(Command com, Displayable dis) {
	String label = com.getLabel();
	
        if ("Next".equals(label)) {    
            myMIDlet.notifyNext("");
        }
    }

    public void itemStateChanged(Item item) {
       if (item == myCaloriesTF) {
           myCalories = Integer.parseInt( ((TextField) item).getString() );
       } else if (item == myTimeTF) {
           myTime = Integer.parseInt( ((TextField) item).getString() );
       } 
    }
    
    private int getCalories() {
        return myCalories;
    }
    
    private int getTime() {
       return myTime; 
    }

    public int[] getDescriptorData() {
        int[] descriptor = {getCalories(), getTime()};
        return descriptor;
    }
}
